import api from '@/service/config/api.js'
import checkTokenMixin from './check_token.js'
export default {
	mixins: [checkTokenMixin],
	data() {
		return {
			banners: [],
			noHideLoading: true,
		}
	},
	methods: {
		getBannerData() {
			return new Promise((resolve, reject) => {
				api.get('/base/api/tAppletBanner/inner/queryByShowLocation', {
					showLocation: this.bannerId,
					tenantId: uni.getStorageSync("tenantId")
				}, {
					noHideLoading: this.noHideLoading
				}).then(res => {
					if (res.data && res.data.length) {
						this.banners = res.data.map(item => ({
							...item,
							url: (this.$utils.getStaticUrl(item.images))
						}))
					}
				}).finally(() => {
					resolve()
				})
				// api.get(this.checkToken?'/base/api/tAppletBanner/queryByShowLocation':'/base/api/tAppletBanner/inner/queryByShowLocation', {
				// 	showLocation: this.bannerId
				// }, {
				// 	noHideLoading: this.noHideLoading
				// }).then(res => {
				// 	if (res.data && res.data.length) {
				// 		this.banners = res.data.map(item => ({
				// 			...item,
				// 			url: (this.$utils.getStaticUrl(item.images))
				// 		}))
				// 	}
				// }).finally(() => {
				// 	resolve()
				// })
			})
		},
		handleClickSwiper(index) {
			console.log(this.$store.state.appType)
			console.log(this.$base.USER_TYPE)
			console.log(this.$storage.getItem('token'))
			// if (this.$store.state.appType==this.$base.USER_TYPE) {
			// 	if(!this.$storage.getItem('token')){
			// 		this.$utils.modalRedirectToLogin()
			// 		return
			// 	}
			// }else {
				// if(!this.$storage.getItem('token')) {
				// 	this.$utils.modalRedirectToLogin()
				// 	return
				// }
				// else 
				if ((this.userType == 3 && this.basicUnserInfo.dealerAuditStatus == 2 && !this
					.basicUnserInfo
					.paySetMeal)){
						this.$utils.showModal({
							title: '提示',
							confirmText: '去购买',
							content: '您还未购买套餐'
						}).then(() => {
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/common/pages/product'
								})
							}, 1500)
						})
						return
					}
			// }
			let url = ''
			switch (this.banners[index].jumpMethod) {
				case '1':
					url = `/pages/common/pages/richtext?id=${this.banners[index].id}&banner=true`
					break;
				case '2':
					url = '/pages/goods/pages/seckill'
					break;
				case '3':
					url = '/pages/goods/pages/rush_purchase'
					break;
				case '4':
					url = '/pages/goods/pages/bargain'
					break;
				case '5':
					url = '/pages/goods/pages/group'
					break;
				case '6':
					url = '/pages/goods/pages/detail?isIntegral=1&id=' + this.banners[index].productId
					break;
				case '7':
					url = '/pages/goods/pages/search?brandId=' + this.banners[index].productId
					break;
				case '9':
					url = '/pages/goods/pages/integral'
					break;
				default:
					break;
			}
			if (url) {
				uni.navigateTo({
					url
				})
			}
		}
	}
}